﻿using BUGCOME.Infrastructure.Attribute;
using BUGCOME.Model.Auth;
using BUGCOME.ServiceCore.Services.IServices;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BUGCOME.ServiceCore.Services
{
    /// <summary>
    /// 角色菜单服务
    /// </summary>
    [AppService(ServiceType = typeof(IRoleMenuService), ServiceLifetime = LifeTime.Transient)]
    public class RoleMenuService : BaseService<RoleMenu>, IRoleMenuService
    {
        /// <summary>
        /// 异步批量添加角色菜单关联
        /// </summary>
        /// <param name="roleMenus">角色菜单关联列表</param>
        /// <returns>插入结果标识</returns>
        public async Task<long> AddRoleMenuAsync(List<RoleMenu> roleMenus)
        {
            return await InsertAsync(roleMenus);
        }

        /// <summary>
        /// 异步检查菜单是否被角色关联
        /// </summary>
        /// <param name="menuId">菜单ID</param>
        /// <returns>是否关联（true是，false否）</returns>
        public async Task<bool> CheckMenuExistRoleAsync(long menuId)
        {
            return await CountAsync(it => it.MenuId == menuId) > 0;
        }
    }
}
